﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Soft
{
    [Serializable]
    public class Information : baseObject
    {
        public Information()
        {
            this.Type = InformationType.Prompt;
        }

        public Information(Exception e, object sender)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            this.Type = InformationType.Exception;
            this.Text = e.ToString();
            this.Sender = sender;
            this.EventTime = DateTime.Now;
        }

        public Information(Exception e) : this(e, null)
        {
        }

        public Information(InformationType type, string text, object sender)
        {
            this.Type = type;
            this.Text = text;
            this.Sender = sender;
            this.EventTime = DateTime.Now;
        }

        public Information(InformationType type, string text) : this(type, text, null)
        {
        }

        public InformationType Type { get; set; }


        public string Text { get; set; }


        [XmlIgnore]
        //[ScriptIgnore]
        //[JsonIgnore]
        public object Sender { get; private set; }


        public DateTime EventTime { get; set; }

        public override string ToString()
        {
            return string.Format("{0} @ {1} -> {2}", this.Text, this.EventTime.ToDateTimeString(false), (this.Sender != null) ? this.Sender.GetType().FullName : "Unknown");
        }
    }
}
